package games.mapacman.common;

import marauroa.common.game.RPClass;
import marauroa.common.game.RPObject;
import marauroa.common.game.Definition.Type;
import marauroa.server.game.Statistics;
import games.mapacman.client.GameScreen;
import games.mapacman.server.MaPacmanZone;

public class Powerpill extends Dot {

	// Number of Turns Power-Mode is active
	private static final int POWER_TIME = 100;
	
	private int powerprob=1;
	private int power_score;
	private boolean isPowerpill;
	
	public Powerpill(int x, int y, int dot_score, int power_score, int power_probability, MaPacmanZone zone) {
		super(x,y,dot_score,zone);
		myObject.put("type",consts.TYPE_POWERPILL);
		myObject.put("powerprob",power_probability);
		myObject.put("score",power_score);
		myObject.put("dottype",TYPE_POWERPILL);
		powerprob = power_probability;
		this.power_score = power_score;
	}
	
	public Powerpill(RPObject object) {
		super(object);
		isPowerpill=(myObject.getInt("dottype")==TYPE_POWERPILL);
	}

	public static void initRPClass()
	{
		RPClass superdot = new RPClass(consts.TYPE_POWERPILL);
		superdot.isA(consts.TYPE_DOT);
		superdot.addAttribute("dottype",Type.INT);
		superdot.addAttribute("powerprob",Type.INT);	
	}
	
	public void setRespawnTime()
	{		
		if (zone.getRandom().nextInt(powerprob)==0)
		{	// Powerpill
			myObject.put("score",power_score);
			myObject.put("dottype",TYPE_POWERPILL);
			setRespawnTime(zone.getPowerpillRespawnTime());			
		}
		else
		{
			myObject.put("dottype",TYPE_DOT);
			myObject.put("score",dot_score);
			setRespawnTime(zone.getDotRespawnTime());
		}		
	}
	
	public void addStats(Statistics stats) {
		if (myObject.getInt("dottype")==TYPE_POWERPILL)
		{
			stats.add("Powerpill eaten",1);
		}
		else super.addStats(stats);
	}
	
	
	public void draw(GameScreen screen) {
		if (isPowerpill)
			screen.draw(screen.getDotSprite(TYPE_POWERPILL),x,y);
		else
			screen.draw(screen.getDotSprite(TYPE_DOT),x,y);		
	}
	
	public void eaten(RPObject object) {
		object.add("power",100);
	}
}
